package com.scilvet.reportcomposer.account;

import org.apache.log4j.Logger;

public class Account {
	
	private AccountID accountID;
	private Amount credit;
	private Amount debit;
	private Amount balance;
	
	private Logger logger = Logger.getLogger(this.getClass());
	
	protected Account(AccountID accountID, Amount credit, Amount debit, Amount balance) {
		this.accountID = accountID;
		this.credit = credit;
		this.debit = debit;
		this.balance = balance;
	}
	
	protected Account(AccountID accountID) {
		this(accountID, Amount.ZERO, Amount.ZERO, Amount.ZERO);
	}
	
	protected void addCredit(Amount additionalCredit) {
		credit = credit.add(additionalCredit);
	}
	
	protected void addDebit(Amount additionalDebit) {
		debit = debit.add(additionalDebit);
	}
	
	protected void addBalance(Amount additionalBalance) {
		balance = balance.add(additionalBalance);
	}
	
	protected void addAmount(Amount amount, AmountType amountType) {
		
		switch (amountType) {
		case CREDIT:
			addCredit(amount);
			break;
		case DEBIT:
			addDebit(amount);
			break;
		case BALANCE:
			addBalance(amount);
			break;
		default:
			logger.warn("AmountType " + amountType + " does not exist.");
			break;
		}
	}
	
	protected void addAmount(Amount credit, Amount debit, Amount balance) {
		addCredit(credit);
		addDebit(debit);
		addBalance(balance);
	}
	
	public AccountID getAccountID() {
		return accountID;
	}
	
	public Amount getCredit() {
		return credit;
	}
	
	public Amount getDebit() {
		return debit;
	}
	
	public Amount getBalance() {
		return balance;
	}
	
	public Amount getAmount(AmountType amountType) {
		
		switch (amountType) {
		case CREDIT:
			return credit;
		case DEBIT:
			return debit;
		case BALANCE:
			return balance;
		default:
			logger.warn("AmountType " + amountType + " does not exist.");
			return Amount.ZERO;
		}
	}
	
	@Override
	public String toString() {
		return accountID.toString() + ": Debit " + debit + ", Credit " + credit + ", Balance " + balance;
	}
}